package com.gaowl.yygh.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaowl.yygh.commom.result.Result;
import com.gaowl.yygh.commom.utils.AuthContextHolder;
import com.gaowl.yygh.enums.OrderStatusEnum;
import com.gaowl.yygh.model.order.OrderInfo;
import com.gaowl.yygh.order.service.OrderService;
import com.gaowl.yygh.vo.order.OrderQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: appointment-register
 * @description: 订单接口控制器类
 * @author: gaowl@stu.jiangnan.edu.cn
 * @create: 2021-04-08 20:13
 **/
@RestController
@RequestMapping("api/order/orderInfo")
public class OrderApiController {

    @Autowired
    private OrderService orderService;
    
    /**
    * @Description: 生成挂号订单
    * @param scheduleId: 排班id
    * @param patientId: 就诊人id
    */
    @PostMapping("auth/submitOrder/{scheduleId}/{patientId}")
    public Result submitOrder(@PathVariable String scheduleId,
                              @PathVariable Long patientId){
        Long order = orderService.saveOrder(scheduleId, patientId);
        return Result.ok(order);
    }


    /**
     * @Description: 查看订单详情
     * @param orderId: 订单id
     */
    @GetMapping("/auth/getOrders/{orderId}")
    public Result getOrders(@PathVariable String orderId){
        OrderInfo orderInfo = orderService.getOrder(orderId);
        return Result.ok(orderInfo);
    }

    /**
     * @Description: 查看订单列表（条件查询带分页）
     * @param page: 当前页
     * @param limit: 每页数据数量
     */
    @GetMapping("auth/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       OrderQueryVo orderQueryVo, HttpServletRequest request) {
        //设置当前用户id
        orderQueryVo.setUserId(AuthContextHolder.getUserId(request));
        Page<OrderInfo> pageParam = new Page<>(page,limit);
        IPage<OrderInfo> pageModel = orderService.selectPage(pageParam,orderQueryVo);
        return Result.ok(pageModel);
    }


    @GetMapping("auth/getStatusList")
    public Result getStatusList() {
        return Result.ok(OrderStatusEnum.getStatusList());
    }
}
